import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class UseAws {
	private static final File PROPERTIES_FILE = new File("config.ini");

	public static void main(String[] args) {
		Properties properties = getProperties();
		AwsInstancesManager awsInstancesManager = new AwsInstancesManager(properties);
		awsInstancesManager.run();
	}

	private static Properties getProperties() {
		Properties properties = new Properties();
		try {
			FileInputStream fileInputStream = new FileInputStream(PROPERTIES_FILE);
			BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
			properties.load(bufferedInputStream);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.out.println(exampleConfigFile());
			System.exit(-1);
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println(exampleConfigFile());
			System.exit(-1);
		}
		return properties;
	}

	private static String exampleConfigFile() {
		System.out.println("EXAMPLE OF CONFIG.INI : ");
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("awsSecretKey=abcdefghijKlmhgOugfh\\dfjjwjhjsdfsf\n");
		stringBuilder.append("awsAccessKeyId=AKERHFDSHSJFHSSJFH\n");
		stringBuilder.append("tokenName=0\n");
		stringBuilder.append("prefixWorker=prefix\n");
		stringBuilder.append("prefixCombiner=prefix\n");
		stringBuilder.append("ami=ami-xyz\n");
		stringBuilder.append("keyname=key\n");
		stringBuilder.append("instanceType=m1.small\n");
		stringBuilder.append("securityGroup=launch-wizard-2\n");
		stringBuilder.append("maxNbInstance=4\n");
		stringBuilder.append("minNbInstance=4\n");
		stringBuilder.append("idClient=c502f049-541e-4e8f-ae69-e6226fc592b3\n");
		stringBuilder.append("addressServer=http://www.lsds-rg.org:8080\n");
		stringBuilder.append("image=exposure\n");
		stringBuilder.append("height=768\n");
		stringBuilder.append("width=1024\n");
		stringBuilder.append("k=4\n");
		stringBuilder.append("povrayModId=437333d2-150c-4775-9961-49237602f254\n");
		stringBuilder.append("combineModId=959ffe03-77d9-4a02-82ce-b0f6c5c54078\n");
		stringBuilder.append("key=key/key.pem\n");
		stringBuilder.append("user=ubuntu\n");
		stringBuilder.append("applicationName=my-app-name\n");
		return stringBuilder.toString();
	}
}
